﻿using System;

using ExtensibleEventViewer.Console.EventArguments;


namespace ExtensibleEventViewer.Console.Forms
{
	public partial class EventLogAdapterSettingsWnd : FormBase
	{
		internal event EventHandler<SaveEventLogAdapterSettingsArgs> SaveSettings;

		public EventLogAdapterSettingsWnd()
		{
			InitializeComponent();
		}

		internal bool EnableRefresh
		{
			get
			{
				return eventLogAdapterSettingsControl.EnableRefresh;
			}
			set
			{
				eventLogAdapterSettingsControl.EnableRefresh = value;
			}
		}

		internal bool UseDefaultRefreshInterval
		{
			get
			{
				return eventLogAdapterSettingsControl.UseDefaultRefreshInterval;
			}
			set
			{
				eventLogAdapterSettingsControl.UseDefaultRefreshInterval = value;
			}
		}

		internal TimeSpan RefreshInterval
		{
			get
			{
				return eventLogAdapterSettingsControl.RefreshInterval;
			}
			set
			{
				eventLogAdapterSettingsControl.RefreshInterval = value;
			}
		}

		private void btnSave_Click(object sender, EventArgs e)
		{
			if(SaveSettings != null)
			{
				SaveEventLogAdapterSettingsArgs args = new SaveEventLogAdapterSettingsArgs
				                                       	{
				                                       		EnableRefresh = eventLogAdapterSettingsControl.EnableRefresh,
				                                       		RefreshInterval = eventLogAdapterSettingsControl.RefreshInterval,
				                                       		UseDefaultRefreshInterval =
				                                       			eventLogAdapterSettingsControl.UseDefaultRefreshInterval
				                                       	};

				SaveSettings(this, args);
			}

			Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			Close();
		}
	}
}
